<?php
// 后台用户模块
class ServeRecordAction extends CommonAction {
	protected $config=array('app_type'=>'master');
	
	function _search_filter(&$map) {
		if (!empty($_POST['keyword'])) {
			$map['emp_name|emp_no'] = array('like', "%" . $_POST['keyword'] . "%");
		}
	}


	function index() {
    import("@.ORG.Page");       //导入分页类
    print_r($_POST);

    $model = D('ServeRecord');
    $serve_record_list = $model -> relation(true) -> where("mini_client_id = ".$id) -> select();

    $param = array(
      'result'=>$serve_record_list,            //分页用的数组或sql
      'listvar'=>'serve_record_list',            //分页循环变量
      'listRows'=>8,            //每页记录数
      'pageUrl' => "serve_record/index/$id",
      'parameter'=>'',//url分页后继续带的参数
      'target'=>'serve_record_content',    //ajax更新内容的容器id，不带#
      'pagesId'=>'serve_record_page',        //分页后页的容器id不带# target和pagesId同时定义才Ajax分页
      'template'=>'MiniKehu:serve_record_ajaxlist',//ajax更新模板
    );
    $this -> page($param);
    $this -> display('MiniKehu:serve_record_ajaxlist');



  }



  // 插入数据
  public function insert() {
    // 创建数据对象
    $model = D("ServeRecord");
    if (!$model -> create()) {
      $this -> error($model -> getError());
    } else {
      $model -> __set('letter', get_letter($model -> __get('emp_name')));
      if ($result = $model -> add()) {
        $this -> assign('jumpUrl', get_return_url());
        $this -> success('用户添加成功！');
			} else {
				$this -> error('用户添加失败！');
			}
		}
	}

	function update() {
		$name = $this -> getActionName();
		$model = D($name);
		if (false === $model -> create()) {
			$this -> error($model -> getError());
		}
		// 更新数据
		$model -> __set('letter', get_letter($model -> __get('emp_name')));
		$list = $model -> save();
		if (false !== $list) {
			//成功提示
			$this -> assign('jumpUrl', get_return_url());
			$this -> success('编辑成功!');
		} else {
			//错误提示
			$this -> error('编辑失败!');
		}
	}

  function del($id=0) {
		$name = $this -> getActionName();
		$model = D($name);
    $model->delete($id);
    $this -> success('删除成功!');
  }


	function json() {
		header("Content-Type:text/html; charset=utf-8");
		$key = $_REQUEST['key'];

		$model = M("ServeRecord");
		//$where['emp_name'] = array('like', "%" . $key . "%");
		//$where['emp_no'] = array('like', "%" . $key . "%");
		$where['_logic'] = 'or';
		$map['_complex'] = $where;
		$list = $model -> where($map) -> field('id,emp_name as name') -> select();
		exit(json_encode($list));
	}

}
?>
